package com.ruoyi.consumer.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.consumer.domain.FUser;
import com.ruoyi.consumer.service.IFUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * f用户账号Controller
 * 
 * @author ruoyi
 * @date 2023-10-16
 */
@RestController
@RequestMapping("/consumer/fuser")
public class FUserController extends BaseController
{
    @Autowired
    private IFUserService fUserService;

    /**
     * 查询f用户账号列表
     */
    @PreAuthorize("@ss.hasPermi('consumer:fuser:list')")
    @GetMapping("/list")
    public TableDataInfo list(FUser fUser)
    {
        startPage();
        List<FUser> list = fUserService.selectFUserList(fUser);
        return getDataTable(list);
    }

    /**
     * 导出f用户账号列表
     */
    @PreAuthorize("@ss.hasPermi('consumer:fuser:export')")
    @Log(title = "f用户账号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FUser fUser)
    {
        List<FUser> list = fUserService.selectFUserList(fUser);
        ExcelUtil<FUser> util = new ExcelUtil<FUser>(FUser.class);
        util.exportExcel(response, list, "f用户账号数据");
    }

    /**
     * 获取f用户账号详细信息
     */
    @PreAuthorize("@ss.hasPermi('consumer:fuser:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Integer userId)
    {
        return success(fUserService.selectFUserByUserId(userId));
    }

    /**
     * 新增f用户账号
     */
    @PreAuthorize("@ss.hasPermi('consumer:fuser:add')")
    @Log(title = "f用户账号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FUser fUser)
    {
        return toAjax(fUserService.insertFUser(fUser));
    }

    /**
     * 修改f用户账号
     */
    @PreAuthorize("@ss.hasPermi('consumer:fuser:edit')")
    @Log(title = "f用户账号", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FUser fUser)
    {
        return toAjax(fUserService.updateFUser(fUser));
    }

    /**
     * 删除f用户账号
     */
    @PreAuthorize("@ss.hasPermi('consumer:fuser:remove')")
    @Log(title = "f用户账号", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Integer[] userIds)
    {
        return toAjax(fUserService.deleteFUserByUserIds(userIds));
    }
}
